import { Injectable } from '@nestjs/common'
import { PrismaService } from 'src/common/prisma/prisma.service'
import { CreateCategoryDto } from './dto/create-category.dto'

@Injectable()
export class CategoryService {
   constructor(private readonly prisma: PrismaService) {}
   findAll() {
      return this.prisma.category.findMany()
   }

   delete(id: number) {
      return this.prisma.category.delete({
         where: {
            id
         }
      })
   }

   add(createCategoryDto: CreateCategoryDto) {
      return this.prisma.category.create({
         data: {
            name: createCategoryDto.name
         }
      })
   }

   // 更新
   update(id: number, createCategoryDto: CreateCategoryDto) {
      return this.prisma.category.update({
         where: {
            id
         },
         data: {
            name: createCategoryDto.name
         }
      })
   }
}
